<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑门票套餐</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('style.css,base.css,base2.css,base_new.css,calendar-price-jquery.min.css'); }
    {Common::getScript("jquery.validate.js,choose.js,product_add.js,jquery.upload.js,DatePicker/WdatePicker.js,layer/layer.js")}
    {Common::css_plugin('ferry_edit.css','ferry')}
    {php echo Common::js_plugin('jquery.datetimepicker.full.js','ferry');}
    {php echo Common::css_plugin('jquery.datetimepicker.css','ferry');}
    <style>
        .dialog-body{
            height: 100%;
            position: relative;
        }
        .dialog-body .save-con{
            position: fixed;
            bottom: 0;
            background: #fff;
            width: 100%;
            text-align: right;
            border-top: solid 1px #e5e5e5;
            padding-top: 10px;
            z-index: 999;
        }
        .dialog-body .product-add-div{
            padding-bottom: 50px;
        }
        .rule-item{
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }
        .rule-item .rule-item-hd{
            width: 100px;
            text-align: right;
        }
    </style>
</head>
<body>
<div class="dialog-body">
    <div class="product-add-div pb-20 mb-20">
        <form id="suit_form" margin_border=RqKsSj >
            <ul class="info-item-block">
                <li>
                    <span class="item-hd item-title">供应商信息</span>
                </li>
                <li>
                    <span class="item-hd">供应商：</span>
                    <div class="item-bd">
                        <a href="javascript:;" class="fl btn btn-primary radius size-M va-t mt-3" onclick="Product.getSupplier(this,'.supplier-sel')" title="选择">选择</a>
                        <div class="save-value-div mt-2 ml-10 supplier-sel w700">
                            {if !empty($info['supplier']['id'])}
                            <span class="mb-5">
                        <s class="del-supplier"></s>
                        {$info['supplier']['suppliername']}
                        <input type="hidden" name="supplier_id" value="{$info['supplier']['id']}">
                    </span>
                            {/if}
                        </div>
                    </div>
                </li>

                <li class="supplier-info {if !$info['supplier']}hide{/if}">
                    <span class="item-hd">供应商ID：</span>
                    <div class="item-bd">
                        <span class="item-text" id="supplier_id">{$info['supplier']['id']}</span>
                    </div>
                </li>
                <li class="supplier-info {if !$info['supplier']}hide{/if}">
                    <span class="item-hd">供应商名称：</span>
                    <div class="item-bd">
                        <span class="item-text" id="supplier_name">{$info['supplier']['suppliername']}</span>
                    </div>
                </li>
                <li class="supplier-info {if !$info['supplier']}hide{/if}">
                    <span class="item-hd">供应商联系人：</span>
                    <div class="item-bd">
                        <span class="item-text" id="supplier_link_man">{if $info['supplier']['linkman']}{$info['supplier']['linkman']} {else} -- {/if}</span>
                    </div>
                </li>
                <li class="supplier-info {if !$info['supplier']}hide{/if}">
                    <span class="item-hd">供应商联系电话：</span>
                    <div class="item-bd">
                        <span class="item-text" id="supplier_link_mobile">{if $info['supplier']['mobile']}{$info['supplier']['mobile']} {else} -- {/if}</span>
                    </div>
                </li>
                <li class="supplier-info {if !$info['supplier']}hide{/if}">
                    <span class="item-hd">结算方式：</span>
                    <div class="item-bd">
                        <label class="radio-label">
                            <input type="radio" name="settlement_type" {if empty($info['settlement_type']) || $info['settlement_type'] == 1}checked{/if} value="1"/>结算价
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="settlement_type" {if !empty($info['settlement_type']) && $info['settlement_type'] == 2}checked{/if}  value="2"/>销售价
                        </label>
                    </div>
                </li>
            </ul>
            <div class="line"></div>
            <ul class="info-item-block">
                <li>
                    <span class="item-hd item-title">门票信息</span>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>门票名称：</span>
                    <div class="item-bd">
                        <input type="text" name="title" id="title" class="input-text w800" value="{$info['title']}"/>
                    </div>
                </li>
                <li>
                    <span class="item-hd">门票类型{Common::get_help_icon('ferry_ticket_type')}：</span>
                    <div class="item-bd">
                <span class="select-box w150">
                <select class="select" name="ticket_type_id" id="ticket_type_id">
                    <option value="">请选择门票类型</option>
                    {loop $info['ticket_type_list'] $ticket_type_list}
                    <option value="{$ticket_type_list['id']}" {if $info['tickettypeid']==$ticket_type_list['id']}selected="selected"{/if} >{$ticket_type_list['kindname']}</option>
                    {/loop}
                </select>
                </span>
                        <input type="text" id="field_newtickettype" name="newtickettype" style="display: none" class="input-text w100" value=""/>
                        <a href="javascript:;" class="btn btn-primary radius size-M mt-1 mr-5" id="newtickettype_btn">添加类型</a>
                    </div>
                </li>
                {if !empty($info['period_time_list'])}
                <li>
                    <span class="item-hd">预约时段：</span>
                    <div class="item-bd">
                        {loop $info['period_time_list'] $period_time}
                        {if in_array($period_time['period_time_id'], $info['ticket_period_time_ids'])}
                        <span data-id="{$period_time['period_time_id']}" class="btn btn-primary radius period-time-btn">
                        {$period_time['date_str']}
                        </span>
                        {else}
                        <span data-id="{$period_time['period_time_id']}" class="btn btn-grey-outline radius period-time-btn">
                        {$period_time['date_str']}
                        </span>
                        {/if}
                        {/loop}
                        <span id="period_time_list">
                            {loop $info['ticket_period_time_ids'] $ticket_period_time}
                            <input type="hidden" name="period_time_id[]" value="{$ticket_period_time}" />
                            {/loop}
                        </span>
                    </div>
                </li>
                {/if}
                <li>
                    <span class="item-hd">原价{Common::get_help_icon('product_original_price')}：</span>
                    <div class="item-bd">
                        <input type="text" name="sellprice" class="input-text w80" value="{$info['sellprice']}"/>
                    </div>
                </li>
                <li>
                    <span class="item-hd">取票方式{Common::get_help_icon('ticket_get_way')}：</span>
                    <div class="item-bd">
                        <input type="text" name="get_ticket_way" class="input-text w800" value="{$info['get_ticket_way']}"/>
                    </div>
                </li>
                <li>
                    <span class="item-hd">门票描述{Common::get_help_icon('ticket_description_content')}：</span>
                    <div class="item-bd">
                        {php Common::getEditor('description',$info['description'],800,200,'Line');}
                    </div>
                </li>
            </ul>
            <div class="line"></div>
            <ul class="info-item-block">
                <li>
                    <span class="item-hd item-title">预订规则</span>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>提前预订时间：</span>
                    <div class="item-bd before-book-time">
                        <label class="radio-label">
                            <input type="radio" {if $info['in_advance_book_type'] == '1'}checked{/if} name="in_advance_book_type" value="1" />用户无需提前购买，且预订成功后立即可用
                        </label>
                        <br>
                        <label class="radio-label mt-10">
                            <input type="radio" {if $info['in_advance_book_type'] == '2'}checked{/if} name="in_advance_book_type" value="2" />
                            预订成功后
                            <input type="text" name="hour_after" class="input-text w80 min-number-valid" data-min="0" value="{$info['hour_after']}" {if $info['in_advance_book_type'] != '2'}disabled{/if}/>
                            小时
                            <input type="text" name="minute_after" class="input-text w80 min-number-valid" data-min="0" value="{$info['minute_after']}" {if $info['in_advance_book_type'] != '2'}disabled{/if}/>
                            分钟后方可使用
                        </label>
                        <br>
                        <label class="radio-label mt-10">
                            <input type="radio" {if $info['in_advance_book_type'] == '3'}checked{/if} name="in_advance_book_type" value="3" />
                            用户需在游玩前
                            {if $info['in_advance_book_type'] == '3'}
                            <input type="text" name="day_before" class="input-text w80 min-number-valid" data-min="0" value="{$info['day_before']}" {if $info['in_advance_book_type'] != '3'}disabled{/if}/>
                            天
                            <input type="text" name="time_before" class="input-text w80" value="{$info['time_before']}" {if $info['in_advance_book_type'] != '3'}disabled{/if}/>
                            {else}
                            <input type="text" name="day_before" class="input-text w80 min-number-valid" data-min="0" {if $info['in_advance_book_type'] != '3'}disabled{/if}/>
                            天
                            <input type="text" name="time_before" class="input-text w80" {if $info['in_advance_book_type'] != '3'}disabled{/if}/>
                            {/if}
                            （景区当地时间）购买，方可使用
                        </label>
                        <br>
                        <label class="radio-label mt-10">
                            <input type="radio" {if $info['in_advance_book_type'] == '4'}checked{/if} name="in_advance_book_type" value="4" />
                            {if $info['in_advance_book_type'] == '4'}
                            用户需在游玩前
                            <input type="text" name="day_before" class="input-text w80 min-number-valid" data-min="0" value="{$info['day_before']}" {if $info['in_advance_book_type'] != '4'}disabled{/if} />
                            天
                            <input type="text" name="time_before" class="input-text w80" value="{$info['time_before']}" {if $info['in_advance_book_type'] != '4'}disabled{/if} />
                            {else}
                            用户需在游玩前
                            <input type="text" name="day_before" class="input-text w80 min-number-valid" data-min="0"  {if $info['in_advance_book_type'] != '4'}disabled{/if} />
                            天
                            <input type="text" name="time_before" class="input-text w80"  {if $info['in_advance_book_type'] != '4'}disabled{/if} />
                            {/if}
                            购买，且预定成功后
                            <input type="text" name="hour_after" class="input-text w80 min-number-valid" data-min="0" value="{$info['hour_after']}" {if $info['in_advance_book_type'] != '4'}disabled{/if} />
                            小时
                            <input type="text" name="minute_after" class="input-text w80 min-number-valid" data-min="0" value="{$info['minute_after']}" {if $info['in_advance_book_type'] != '4'}disabled{/if} />
                            分钟后方可使用
                        </label>
                    </div>
                </li>

                <li>
                    <span class="item-hd">起售：</span>
                    <div class="item-bd">
                        <label class="radio-label ">
                            至少
                            <input type="number" name="at_least" class="input-text w80 min-number-valid" value="{$info['at_least']}"  />
                            件起售  &nbsp;&nbsp;&nbsp;*起售数量超出库存时，买家无法购买该产品；多套餐预订 起售规则无效
                        </label>
                    </div>
                </li>

                <li>
                    <span class="item-hd">有效期{Common::get_help_icon('ticket_check_effective_days')}：</span>
                    <div class="item-bd">
                        游客指定入园日期后 <input type="number" name="effective_days" class="input-text w50 min-number-valid" data-min="0" value="{$info['effective_days']}"/> 天内有效
                    </div>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>会员预订方式{Common::get_help_icon('order_pay_type')}：</span>
                    <div class="item-bd">
                        <div class="on-off">
                            <label class="radio-label">
                                <input type="radio" name="paytype" value="1" {if $info['paytype']=='1' OR empty($info['paytype'])}checked="checked"{/if} />全额预订
                            </label>
                            <label class="radio-label ml-20">
                                <input type="radio" name="paytype" id="field_paytype_2" value="2" {if $info['paytype']=='2'}checked="checked"{/if} />定金预订
                            </label>
                            <span id="dingjin" style="{if $info['paytype'] != '2'}display: none{/if}">
                        每人支付定金 <input type="text" class="input-text w60 va-t" maxlength="6" name="dingjin" id="dingjintxt" value="{$info['dingjin']}" size="6" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-\.]+/,'');}).call(this)" onblur="this.v();">&nbsp;
                    </span>
                            <script>

                            </script>
                        </div>
                    </div>
                </li>
                <li>
                    <span class="item-hd">限购条件：</span>
                    <div class="item-bd">
                        <label class="check-label">
                            <input type="checkbox" {if $info['is_open_limit_order_num']=='1'}checked="checked"{/if} name="is_open_limit_order_num" value="1" />开启
                        </label>
                        每笔订单限购数量
                        <input type="text" name="limit_order_num" class="input-text w80 min-number-valid" data-min="1" value="{$info['limit_order_num']}"/>
                        <br>
                        <label class="check-label mt-10">
                            <input type="checkbox" {if $info['is_open_member_limit']=='1'}checked="checked"{/if} name="is_open_member_limit" value="1" />开启
                        </label>
                        每个会员ID限购订单数
                        <input type="text" name="member_limit_order_num" class="input-text w80 min-number-valid" data-min="1" value="{$info['member_limit_order_num']}"/>
                    </div>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>预订确认方式{Common::get_help_icon('order_need_confirm')}：</span>
                    <div class="item-bd">
                        <label class="radio-label">
                            <input type="radio" name="need_confirm" value="0" {if !$info['need_confirm']}checked="checked"{/if} />无需确认
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="need_confirm" value="1" {if $info['need_confirm']=='1'}checked="checked"{/if} />支付后确认
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="need_confirm" value="2" {if $info['need_confirm']=='2'}checked="checked"{/if} />支付前确认
                        </label>
                    </div>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>待付款时限{Common::get_help_icon('order_auto_close_time')}：</span>
                    <div class="item-bd">
                        <input type="text" name="auto_close_time_hour min-number-valid" data-min="0" id="auto_close_time_hour" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" class="input-text w60" {if $action=='add'}value="24"{else}value="{$info['auto_close_time_hour']}"{/if}/>&nbsp;小时
                        <input type="text" name="auto_close_time_minute min-number-valid" data-min="0" id="auto_close_time_minute" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" class="input-text w60" {if $action=='add'}value="0"{else}value="{$info['auto_close_time_minute']}"{/if}/>&nbsp;分钟
                    </div>
                </li>
                <li class="auto_confirm_time" style="{if $info['need_confirm'] != 1}display:none;{/if}">
                    <span class="item-hd"><i class="c-red">*</i>待确认时限{Common::get_help_icon('order_confirm_close_time')}：</span>
                    <div class="item-bd">
                        <input type="text" name="auto_confirm_time_hour min-number-valid" data-min="0" id="auto_confirm_time_hour" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" class="input-text w60" {if $action=='add'}value="24"{else}value="{$info['auto_confirm_time_hour']}"{/if}/>&nbsp;小时

                        <input type="text" name="auto_confirm_time_minute min-number-valid" data-min="0" id="auto_confirm_time_minute" maxlength="2" onkeyup="value=value.replace(/[^\d]/g,'')" class="input-text w60" {if $action=='add'}value="0"{else}value="{$info['auto_confirm_time_minute']}"{/if}/>&nbsp;分钟
                    </div>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>会员支付方式{Common::get_help_icon('order_pay_way')}：</span>
                    <div class="item-bd">
                        <label class="radio-label">
                            <input type="checkbox" name="pay_way[]" id="online_pay" value="1" {if $info['pay_way']=='1' || $info['pay_way']==3}checked="checked"{/if} {if $action=='add'}checked="checked"{/if} />线上支付
                        </label>
                        <label class="radio-label">
                            <input type="checkbox" name="pay_way[]" id="offline_pay" value="2" {if $info['pay_way']=='2' || $info['pay_way']==3}checked="checked"{/if} {if $action=='add'}checked="checked"{/if} {if $info['paytype']=='2'} disabled="disabled" {/if} />线下支付
                        </label>
                    </div>
                </li>
            </ul>
            <div class="line"></div>
            <ul class="info-item-block">
                <li>
                    <span class="item-hd item-title">退改规则</span>
                </li>
                <!--退款规则-->
                {include "admin/ferry/suit/refund_rule"}
                <!--退款规则-->
            </ul>
            <div class="line"></div>
            <ul class="info-item-block">
                <li>
                    <span class="item-hd item-title">游客填写信息</span>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>联系人信息：</span>
                    <div class="item-bd">
                        <label class="check-label">
                            <input type="checkbox" disabled name="fill_link_man[]" value="phone" checked />手机号
                        </label>
                        <label class="check-label ml-20">
                            <input type="checkbox" name="fill_link_man[]" value="email" {if in_array('email',$info['fill_link_man'])}checked="checked"{/if} />邮箱
                        </label>
                    </div>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>游客信息：</span>
                    <div class="item-bd">
                        <label class="radio-label">
                            <input type="radio" name="fill_tourer_type" value="0" {if empty($info['fill_tourer_type'])}checked="checked"{/if} />无需游客信息（推荐）
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="fill_tourer_type" value="1" {if $info['fill_tourer_type']=='1'}checked="checked"{/if} />只需要填写一个游客信息
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="fill_tourer_type" value="2" {if $info['fill_tourer_type']=='2'}checked="checked"{/if} />需填写每一个游客的信息（请慎重选择）
                        </label>
                    </div>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>游客信息必填项：</span>
                    <div class="item-bd">
                        <label class="radio-label">
                            <input type="radio" name="fill_tourer_credential_type" value="1" {if $info['fill_tourer_credential_type'] == '1'}checked="checked"{/if} />不需要证件
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="fill_tourer_credential_type" value="2" {if $info['fill_tourer_credential_type']=='2'}checked="checked"{/if} />需要身份证
                        </label>
                        <label class="radio-label ml-20">
                            <input type="radio" name="fill_tourer_credential_type" value="3" {if $info['fill_tourer_credential_type']=='3'}checked="checked"{/if} />需要有效证件
                        </label>
                        <div class="bg-grey pt-10 pb-10 pl-15 pr-15 w700 mb-10">
                            <div class="item-text">基础信息：中/英文姓名</div>
                            <div class="item-text">证件类型：身份证、护照、学生证、军官证、驾驶证、回乡证、台胞证、港澳通行证、外国人永久居留证、台湾通行证</div>
                        </div>
                    </div>
                </li>
            </ul>

            {if $info['people_rule'] && count($info['people_rule']) > 0}
            <div class="line"></div>
            <ul class="info-item-block mb-20">
                <li>
                    <span class="item-hd item-title">人群规则</span>
                </li>
                <li>
                    <span class="item-hd"><i class="c-red">*</i>人群：</span>
                    <div class="item-bd">
                        {loop $info['people_rule'] $people_rule}
                        <label class="check-label mr-15">
                            <input type="radio" {if !empty($people_rule['rule'])}checked{/if} name="people_group_id" value="{$people_rule['people_group_id']}" />{$people_rule['name']}
                        </label>
                        {/loop}
                        {loop $info['people_rule'] $people_rule}
                        <div id="people_group_id_{$people_rule['people_group_id']}" class="people-group-list bg-grey pt-10 pb-10 pl-15 w700 mb-10 {if empty($people_rule['rule'])}hide{/if}">
                            <ul class="info-item-block">
                                <li>
                                    <span class="item-hd">人群限购：</span>
                                    <div class="item-bd"><span class="item-text">{$people_rule['des']}</span></div>
                                </li>
                                <li>
                                    <span class="item-hd"><i class="c-red">*</i>单位人数：</span>
                                    <div class="item-bd">
                                        <input type="text" maxlength="3" name="unit_num[{$people_rule['people_group_id']}]" onkeyup="value=value.replace(/[^\d]/g,'')" value="{if !empty($people_rule['rule']['unit_num'])}{$people_rule['rule']['unit_num']}{else}1{/if}" class="input-text w60 min-number-valid" data-min="1"/> 人/份
                                    </div>
                                </li>
<!--                                <li>-->
<!--                                    <span class="item-hd"><i class="c-red">*</i>是否免费：</span>-->
<!--                                    <div class="item-bd">-->
<!--                                        <label class="radio-label">-->
<!--                                            <input type="radio" name="is_free[{$people_rule['people_group_id']}]" value="1" {if !empty($people_rule['rule']) && $people_rule['rule']['is_free'] == 1}checked="checked"{/if} />是-->
<!--                                        </label>-->
<!--                                        <label class="radio-label ml-20">-->
<!--                                            <input type="radio" name="is_free[{$people_rule['people_group_id']}]" value="0" {if empty($people_rule['rule'])  || $people_rule['rule']['is_free'] == 0 }checked="checked"{/if} />否-->
<!--                                        </label>-->
<!--                                    </div>-->
<!--                                </li>-->
<!--                                <li>-->
<!--                                    <span class="item-hd"><i class="c-red">*</i>购买方式：</span>-->
<!--                                    <div class="item-bd">-->
<!--                                        <label class="radio-label">-->
<!--                                            <input type="radio" name="buy_type[{$people_rule['people_group_id']}]" value="1" {if !empty($people_rule['rule']) && $people_rule['rule']['buy_type'] == 1}checked="checked"{/if} />可单独购买-->
<!--                                        </label>-->
<!--                                        <label class="radio-label ml-20">-->
<!--                                            <input type="radio" name="buy_type[{$people_rule['people_group_id']}]" value="2" {if empty($people_rule['rule']) || $people_rule['rule']['buy_type'] == 2}checked="checked"{/if} />不可单独购买-->
<!--                                        </label>-->
<!--                                    </div>-->
<!--                                </li>-->
<!--                                <li>-->
<!--                                    <span class="item-hd">可预订份数：</span>-->
<!--                                    <div class="item-bd">-->
<!--                                        最少购买 <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" value="{if !empty($people_rule['rule'])}{$people_rule['rule']['buy_min_num']}{/if}" name="buy_min_num[{$people_rule['people_group_id']}]" maxlength="3" class="input-text w60 min-number-valid" data-min="1"/>  份，最多购买-->
<!--                                        <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" value="{if !empty($people_rule['rule'])}{$people_rule['rule']['buy_max_num']}{/if}" name="buy_max_num[{$people_rule['people_group_id']}]" maxlength="3" class="input-text w60 min-number-valid" data-min="1"/> 份-->
<!--                                    </div>-->
<!--                                </li>-->
                            </ul>
                        </div>
                        {/loop}
                    </div>
                </li>
            </ul>
            {/if}

            <input type="hidden" name="ticket_id" value="{$info['id']}"/>
            <input type="hidden" name="ferry_id" value="{$info['ferryid']}"/>
        </form>
    </div>

    <div class="save-con ">
        <a href="javascript:;" class="btn btn-default size-M mr-30" id="clone_btn">克隆</a>
        <a href="javascript:;" class="btn btn-primary size-M mr-30" id="confirm_btn">保存</a>
    </div>
</div>
</body>
<script type="text/javascript">
    $(document).ready(function() {
        // 日期填写
        $('input[name=time_before]').datetimepicker({
            format: 'H:i',
            datepicker: false,
            timepicker: true,
            allowTimes: [
                '00:30','01:00',
                '01:30','02:00',
                '02:30','03:00',
                '03:30','04:00',
                '04:30','05:00',
                '05:30','06:00',
                '06:30','07:00',
                '07:30','08:00',
                '08:30','09:00',
                '09:30','10:00',
                '10:30','11:00',
                '11:30','12:00',
                '12:30','13:00',
                '13:30','14:00',
                '14:30','15:00',
                '15:30','16:00',
                '16:30','17:00',
                '17:30','18:00',
                '18:30','19:00',
                '19:30','20:00',
                '20:30','21:00',
                '21:30','22:00',
                '22:30','23:00',
                '23:30','00:00',
            ]
        });

        // 数字填写修正
        $(".min-number-valid").on('blur', function (e) {
            var value = $(this).val(),
                min = $(this).data('min');
            min = min === 0 ? 0 : '';
            if (value < 0) {
                $(this).val(min);
            }

            if (!/^[1-9][0-9]*$/.test(value)) {
                $(this).val(min);
            }
        })

        // 供应商------------------
        // 选择供应商
        Product.getSupplier = function(dom,selector,typeid)
        {
            var supplier='';
            $(selector+" input:hidden").each(function(index,ele){
                supplier+=$(ele).val()+',';
            });
            supplier=supplier?supplier.slice(0,-1):'';
            CHOOSE.setSome("设置供应商",{loadWindow:window,loadCallback:Product.listSupplier,maxHeight:500},SITEURL+'supplier/dialog_set?typeid='+(typeid==undefined?0:typeid)+'&suppliers='+supplier+'&selector='+encodeURI(selector),1);
        };

        Product.listSupplier = function(result,bool)
        {
            if(result.data.length > 0) {
                var html="", data = result.data[0];
                html+="<span class='mb-5'><s class='del-supplier'></s>"+ data.suppliername+"<input type='hidden' name='supplier_id[]' value='"+ data.id+"'/></span>";
                $(result.selector).html(html);

                showSupplierInfo(data)
            }
        }
        // 展示供应商数据
        function showSupplierInfo(supplierInfo)
        {
            var settlementType = $("input[name=settlement_type]").val();
            $(".supplier-info").removeClass('hide');
            $("#supplier_id").text(supplierInfo.id);
            $("#supplier_name").text(supplierInfo.suppliername);
            var linkman = supplierInfo.linkman && supplierInfo.linkman !== 'null' ? supplierInfo.linkman : '--',
            mobile = supplierInfo.linkman && supplierInfo.mobile !== 'null' ? supplierInfo.mobile : '--';
            $("#supplier_link_man").text(linkman);
            $("#supplier_link_mobile").text(mobile);
            if(settlementType === '2') {
                $(".settlement-key").removeClass('hide');
            }else{
                $(".settlement-key").addClass('hide');
            }
        }
        // 删除供应商
        $(".supplier-sel").on('click', '.del-supplier',function() {
            $(".supplier-info").addClass('hide');
            $(this).parent().remove();
            // 将结算模式设置为结算价
            $("input[name=settlement_type]").eq(0).prop('checked', true);
        })
        // 切换供应商结算方式
        $("input[name=settlement_type]").on('change', function() {
            var value = $(this).val();
            if(value === '2') {
                $(".settlement-key").removeClass('hide');
            }else{
                $(".settlement-key").addClass('hide');
            }
        })
        // 切换抽佣方式
        $("input[name=settlement_key]").on('change', function () {
            var value = $(this).val(),
                str = parseInt(value) === 2 ? '元' : '%';
            $(".settlement-val-unit").text(str);
        })

        // 预约时段-------------------------
        $(".period-time-btn").on('click', function() {
            $(this).toggleClass('btn-primary').toggleClass('btn-grey-outline');
            var obj = $('.period-time-btn.btn-primary'), html = '';
            obj.each(function(index, item){
                var id = $(item).data('id');
                html += '<input type="hidden" name="period_time_id[]" value="'+id+'" />';
            })

            $("#period_time_list").html(html)
        })

        // 提前预定------------------------
        $(".before-book-time").on('change', 'input[type="radio"]', function(){
            var parent = $(this).parent();
            parent.parent().find('.input-text').prop('disabled', true);
            parent.find('.input-text').prop('disabled', false);
        })

        // 确认按钮切换
        $('input[name="need_confirm"]').change(function() {
            var selectedValue = $(this).val();
            if(selectedValue==1){
                $('.auto_confirm_time').show()
            }else{
                $('.auto_confirm_time').hide()
            }
        });


        // 会员预订方式
        if ($("#field_paytype_2:checked").length > 0) {
            $("#field_paytype_2").trigger('click');
        }

        $("input[name='paytype']").click(function () {
            if ($("#field_paytype_2:checked").length > 0) {
                $("#dingjin").show();
                $("#online_pay").attr('checked', true);
                $('#offline_pay').attr('checked', false);
                $('#offline_pay').attr('disabled', true);
            } else {
                $("#dingjin").hide();
                $("#online_pay").attr('checked', false);
                $('#offline_pay').attr('checked', false);
                $("#online_pay").attr('disabled', false);
                $('#offline_pay').attr('disabled', false);
            }
        })

        // 添加门票类型-----------------------
        function add_tickettype() {
            var ferryId = $("input[name=ferry_id]").val();
            var name = $("#field_newtickettype").val();
            name = $.trim(name);
            if (!name) {
                ST.Util.showFailureMsg('类型名称不能为空');
                return;
            }

            $.ajax({
                data: {name: name, ferry_id: ferryId},
                dataType: 'json',
                type: 'post',
                url: SITEURL + 'ferry/admin/ferry/ajax_add_ticket_type',
                success: function (result) {
                    if (result.status) {
                        var data = result.data;
                        var option_html = "<option selected='selected' value='" + data.id + "'>" + data.kindname + "</option>"
                        $("#ticket_type_id").append(option_html);
                        $("#field_newtickettype").hide();
                        $("#newtickettype_btn").text('添加类型');
                        ST.Util.showMsg('添加门票类型成功', 4, 1000);
                    } else {
                        ST.Util.showMsg(result.msg, 5, 1000);
                    }
                }
            })
        }

        //添加类型按钮
        $("#newtickettype_btn").click(function () {
            if ($('#field_newtickettype').is(':visible')) {
                add_tickettype();
            } else {
                $("#field_newtickettype").show();
                $("#newtickettype_btn").text('确定');
            }
        });

        {if count($people_rule) > 0}
        // 如果没有选择人群，默认选择第一个
        var hasPeopleObj = $("input[name=people_group_id]:checked");
        if (hasPeopleObj.length === 0) {
           var defaultObj = $("input[name=people_group_id]").eq(0);

            defaultObj.trigger('click');

            changePeopleGroup(defaultObj);
        }

        // 人群规则选择
        $("input[name=people_group_id]").on('click', function () {
            changePeopleGroup(this)
        });

        function changePeopleGroup(obj) {
            var id = $(obj).val(),
                select = "#people_group_id_" + id;
            $(".people-group-list").addClass('hide');
            $(select).removeClass('hide');
        }
        {/if}

        // 保存
        $("#confirm_btn").on('click', function () {
            {if count($people_rule) > 0}
            var checkPeopleRuleRes = checkPeopleRule()
            if(!checkPeopleRuleRes.status) {
                ST.Util.showFailureMsg(checkPeopleRuleRes.msg);
                return false;
            }
            {/if}
            var ticket_type_id = $("[name='ticket_type_id']").find('option:selected').val();
            if (!ticket_type_id) {
                ST.Util.showFailureMsg('请选择门票类型');
                return false;
            }

            ST.Util.showLoading('保存中', 10000)
            var frm_data = $("#suit_form").serialize();
            $.ajax({
                data: frm_data,
                dataType: 'json',
                type: 'post',
                url: SITEURL + 'ferry/admin/ferry/ajax_save_ticket',
                success: function (result) {
                    if (result.status) {
                        ST.Util.showSuccessMsg(result.msg);
                        setTimeout(function () {
                            ST.Util.responseDialog({},true);
                        }, 1500)
                    } else {
                        ST.Util.showMsg(result.msg, 5, 1000);
                    }
                }
            })
        })

        // 人群选择验证
        function checkPeopleRule() {
            var status = true, msg;
            try {
                var ruleObjs = $("input[name=people_group_id]:checked");
                if (ruleObjs.length === 0) {
                    throw '请选择一个人群';
                }

                ruleObjs.each(function (index, item) {
                    var id = item.value,
                        parent = $("#people_group_id_" + id),
                        unitNum = parent.find("input[name*=unit_num]").val(),
                        buyMinNum = parent.find("input[name*=buy_min_num]").val(),
                        buyMaxNum = parent.find("input[name*=buy_max_num]").val();
                    if (unitNum === '') {
                        throw '请填写单位人数';
                    }

                    if (buyMinNum && buyMaxNum) {
                        if (buyMinNum > buyMaxNum) {
                            throw '可预订最大份数不能小于最小份数';
                        }
                    }
                })
            } catch (e) {
                status = false;
                msg = e;
            }

            return {status, msg}
        }

        $("#cancel-btn").click(function(){
            ST.Util.closeDialog();
        });

        $('#clone_btn').click(function(){
            var ticket_id = $("[name='ticket_id']").val();
            layer.open({
                type: 1,
                area: ['250px', '200px'],
                shade: '0',
                title: '克隆数量',
                content: '<div class="ml-20 mt-20">' +
                    '<p class="mb-20">克隆前请确保门票信息已保存</p>' +
                    '克隆数量：<input type="text" id="clone-quantity" style="height: 25px" oninput="validateInput(event)">' +
                    '</div>',
                btn: ['确定', '取消'],
                yes: function(index, layero) {
                    layer.msg('克隆中', {
                        icon: 16,
                        shade: '0',
                        time: 0,
                    });
                    var number = $('#clone-quantity').val();
                    $.ajax({
                        data: {number:number,ticket_id:ticket_id},
                        dataType: 'json',
                        type: 'post',
                        url: SITEURL + 'ferry/admin/ferry/ajax_clone_ticket',
                        success: function (result) {
                            if (result.status) {
                                ST.Util.showSuccessMsg(result.msg);
                                setTimeout(function () {
                                    layer.closeAll();
                                    ST.Util.responseDialog({},true);
                                }, 1500)
                            } else {
                                ST.Util.showMsg(result.msg, 5, 1000);
                            }
                        }
                    })
                }
            });
        });
    })

    function validateInput(event) {
        var input = event.target;
        input.value = input.value.replace(/[^\d]/g, ''); // 只保留数字
    }
</script>
</html>